﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Collections.ObjectModel;
using System.Linq;
using Microsoft.Phone.Tasks;
using System.Text;

namespace CapstoneWinPhone.Data
{
    public class DataMethods
    {
        public static bool PasswordChecker(string password1, string password2)
        {
            if (password1.Length != password2.Length)
                return false;
            for (int i = 0; i < password1.Length; i++)
                if (password1[i] != password2[i])
                    return false;

            return true;
        }

        //Use TimeSpan instead of calculating it by force
        public static double CalculateHours(DateTime startTime, DateTime endTime)
        {
            return endTime.Subtract(startTime).TotalHours;
        }

        public static double CalculateMinutes(DateTime startTime, DateTime endTime)
        {
            return endTime.Subtract(startTime).Minutes;
        }

        public static void ComposeEmailTimesheet(WeeklyTimeStamps wts)
        {
            EmailComposeTask emailcomposer = new EmailComposeTask();
            emailcomposer.To = "";
            emailcomposer.Subject = DataHolder._currentUser._username + " " + wts.ToString() + " timesheet";
            StringBuilder strbud = new StringBuilder();
            strbud.Append(DataHolder._currentUser._username + " timesheet\n");
            strbud.Append("They work during these times this week: " + "\n");
            foreach (Timestamps t in wts.listOfTimestamps)
            {
                strbud.Append("" + t.ToString() + "\n");
            }
            strbud.Append("\n\n Total Time: " + wts.TotalHoursAndMinutes());
            emailcomposer.Body = strbud.ToString();
            emailcomposer.Show();
        }

        

        public static void ComposeEmailExpenseReport(ExpenseLog el)
        {
            EmailComposeTask emailcomposer = new EmailComposeTask();
            emailcomposer.To = "";
            emailcomposer.Subject = DataHolder._currentUser._username + " Expense Report";
            StringBuilder strbud = new StringBuilder();
            strbud.Append(DataHolder._currentUser._username + " Expense Report\n");
            strbud.Append("Expense sheet " + el._nameOfLog +": " + "\n");
            strbud.Append("Place of Purchase - Amount spent");
            foreach (Expense e in el._ListOfExpenses)
            {
                strbud.Append("" + e.PlaceOfPurchase + " - " + e.Amount +"\n");
                strbud.Append("     " + e.Description + "\n");
            }
            strbud.Append("\n\n Total amount: " + el._totalAmount);
            emailcomposer.Body = strbud.ToString();
            emailcomposer.Show();
        }

        public static void ComposeEmailMileageReport(MileageReport mr)
        {
            EmailComposeTask emailcomposer = new EmailComposeTask();
            emailcomposer.To = "";
            emailcomposer.Subject = DataHolder._currentUser._username + " Mileage Report";
            StringBuilder strbud = new StringBuilder();
            strbud.Append(DataHolder._currentUser._username + " Mileage Report\n");
            strbud.Append("Mileage report " + mr._name + ": " + "\n");
            strbud.Append("Mileage Report information: " + mr._description + "\n");
            foreach (Trip t in mr._trips)
            {
                strbud.Append("" + t.date.ToShortDateString() + " - " + t.TotalMileage + "\n");
            }
            strbud.Append("\n\n Total milage: " + mr._TotalMiles);
            emailcomposer.Body = strbud.ToString();
            emailcomposer.Show();
        }
    }
}
